package com.hod.client.charge;

import com.google.gwt.core.client.GWT;
import com.google.gwt.gears.client.database.DatabaseException;
import com.google.gwt.gears.client.database.ResultSet;
import com.google.gwt.user.client.Window;
import com.hod.client.backend.orm.client.GearsDataStore;

public class ChargeRecordset {
	
    public static double calculateTotalCharges(String idLodging){
    	GearsDataStore dsCharges = (GearsDataStore) GWT.create(Charge.class);
    	try {
			ResultSet rs = dsCharges.getQuery(Charge.SUM_BY_ID_LODGING.replace("?",idLodging)); //ejecuto directamente el SQL			
			Window.alert(Charge.SUM_BY_ID_LODGING.replace("?",idLodging));
			Double total = rs.getFieldAsDouble(0);
			Window.alert(""+total);
			if (total==null) total = 0.0;
			return total;
		} catch (DatabaseException e) {
			// TODO Auto-generated catch block
			Window.alert(e.getMessage());
			return 0;
		}
    	
    	
    }
}
